<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box{
            width: 150px;
            height: 150px;
            background: red;
            border-radius: 50%;
            position: relative;
        }
        #box #btn{
            position: absolute;
            left: 36%;
            top: 40%;
        }
    </style>
</head>
<body>
    <div id="box">
        <input type="button" name="" id="btn" value="回放">
    </div>
</body>
<script>
    window.onload = function(){
        let box = document.getElementById('box');
        let btn = document.getElementById('btn');
        let arr = [];
        box.onmousedown = function(eve){
            var down = eve || window.event;
            window.onmousemove = function(eve){
                var e = eve || window.event;
                var l = e.pageX - down.offsetX;
                var t = e.pageY - down.offsetY;
                if(l < 0){l = 0}    //设置左边为0
                if(t < 0){t = 0}    //设置上边为0

                if(l > document.documentElement.clientWidth - box.offsetWidth){
                    l = document.documentElement.clientWidth - box.offsetWidth          //右：浏览器的可视区域的宽度 - 当前元素的宽度
                }
                if(t > document.documentElement.clientHeight - box.offsetHeight){
                    t = document.documentElement.clientHeight - box.offsetHeight        //下：浏览器的可视区域的宽度 - 当前元素的宽度
                }
                arr.push({x:l,y:t});                //记录每次滑动轨迹
                
                box.style.left = l + 'px';
                box.style.top = t + 'px';
            }
            window.onmouseup = function(){
                window.onmousemove = null;
            }
        }
        btn.onclick = function(){
            var playback = setInterval(function () {
                if(arr.length > 0){
                    var data = arr.pop();                //滑动最后一次在原地   pop删除最后一次  
                    box.style.left = data.x + 'px';         
                    box.style.top = data.y + 'px';
                }else{
                    clearInterval(playback)
                }
            },15)
        }
    }
</script>
</html>